/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gob.pnp.despachadores;
import java.util.*;
import pe.gob.pnp.actions.*;
import java.sql.*;
import oracle.jdbc.OracleTypes;
import pe.gob.pnp.factories.ConnectionPool;
/**
 *
 * @author Administrador
 */
public class ConceptoPerciboDespachador {


    public static List<ConceptoPercibo> obtenerConceptoPersibo() throws SQLException
    {
             List<ConceptoPercibo> lstConceptoPersibo = new ArrayList<ConceptoPercibo>();
            Connection conn = null;
            try {
                conn = ConnectionPool.obtenerConexion();
                String sql = "{call SP_OBTENER_CONCEPTO_PERCIBO(?)}";
                CallableStatement cs = conn.prepareCall(sql);
                cs.registerOutParameter(1, OracleTypes.CURSOR);
                cs.execute();
                ResultSet rs = (ResultSet) cs.getObject(1);
                while (rs.next())
                {
                    ConceptoPercibo conceptopercibo = new ConceptoPercibo();
                    conceptopercibo.setNcopeIdentificador(rs.getInt("NCOPE_IDENTIFICADOR"));
                    conceptopercibo.setCcopeDescripcion(rs.getString("CCOPE_DESCRIPCION"));
                    conceptopercibo.setDcopeFechaCreacion(rs.getDate("DCOPE_FECHACREACION"));
                    conceptopercibo.setBcopeActivo(rs.getBoolean("BCOPE_ACTIVO"));
                    lstConceptoPersibo.add(conceptopercibo);
                }
            }finally{
              ConnectionPool.liberarConexion(conn);
            }
            return lstConceptoPersibo;
      }

    public static void agregarConceptoPercibo(ConceptoPercibo conceptopersibo)throws SQLException
    {
        Connection conn = null;

        try {
            conn = ConnectionPool.obtenerConexion();
            String sql = "{call SP_AGREGAR_CONCEPTO_PERCIBO(?,?)}";
            CallableStatement cs = conn.prepareCall(sql);
            cs.setString(1, conceptopersibo.getCcopeDescripcion());
            cs.setInt(2, conceptopersibo.isBcopeActivo()? 1:0);
            cs.execute();
        } finally {
            ConnectionPool.liberarConexion(conn);
        }
    }

    public static void modificarConceptoPercibo(ConceptoPercibo conceptopercibo)throws SQLException
    {
        Connection conn = null;

        try {
            conn = ConnectionPool.obtenerConexion();
            String sql = "{call SP_MODIFICAR_CONCEPTO_PERCIBO(?,?,?)}";
            CallableStatement cs = conn.prepareCall(sql);
            cs.setString(1, conceptopercibo.getCcopeDescripcion());
            cs.setInt(2, conceptopercibo.isBcopeActivo()? 1:0);
            cs.setInt(3, conceptopercibo.getNcopeIdentificador());
            cs.execute();
        } finally {
            ConnectionPool.liberarConexion(conn);
        }
    }

}
